	<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('enterprise_edit_page_title'));
$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.all.css')
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'enterprise_enterprise_list'); ?>"><?php echo $this->translator('enterprise_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('enterprise_edit_breadcump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<form method="post" action="<?php echo $this->url(array('enterprise_id' => $this->enterprise_id), 'enterprise_enterprise_edit'); ?>" id="editEnterpriseForm">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('enterprise_edit_guide'); ?></div>

<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <?php if(!$this->isAllowed):?>
            <?php echo $this->translator('enterprise_not_edit_basic_guide'); ?>
        <?php else:?>
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_application'); ?>:</label>
			<select name="application">				
				<option value="0" <?php if(isset($this->enterprise->application) &&  ($this->enterprise->application == 0)) echo "selected='selected'";?>><?php echo $this->translator("application_zero");?></option>
				<option value="1" <?php if(isset($this->enterprise->application) &&  ($this->enterprise->application == 1)) echo "selected='selected'";?>><?php echo $this->translator("application_one");?></option>
			</select>			
        </div>
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_company_name_vn'); ?>:</label>
            <input type="text" id="company_name_vn" name="company_name_vn" style="width: 300px" value="<?php if (null != $this->enterprise && null != $this->enterprise->company_name_vn) : ?><?php echo $this->escape($this->enterprise->company_name_vn); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_company_name_en'); ?>:</label>
            <input type="text" id="company_name_en" name="company_name_en" style="width: 300px" value="<?php if (null != $this->enterprise && null != $this->enterprise->company_name_en) : ?><?php echo $this->escape($this->enterprise->company_name_en); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_professtions'); ?>:</label>
            <div style="border:1px solid #222222; padding: 5px; width:605px;overflow:auto;height:200px">
                <?php for ($i = 0; $i < count($this->professions); $i++) : ?>
                <div style="width:195px; float:left; font-size:7pt; padding-left:2px;">
                    <input <?php if(strstr($this->enterprise->professions_id,','.$this->professions[$i]->professions_id.',')):?> checked <?php endif;?> type="checkbox" id="professions_id[]" name="professions_id[]" value="<?php echo $this->professions[$i]->professions_id; ?>" > <?php echo $this->professions[$i]->professions_name; ?><br>
                </div>
                <?php endfor; ?>
            </div>
            <input type="hidden" value="<?php echo $this->enterprise->professions_id;?>" name="old_professions" />
        </div>

        <hr/>
		
        <!-- Thong bao ti le khi thay doi loai tien te -->
        <div class="clearfix t_a_bottom message" id="note_rate" style="display: none;">
        	<label><?php echo $this->translator('enterprise_note_rare_currency'); ?></label>
        </div>
        
        <div class="clearfix t_a_bottom">
        	<div style="float: left;">
        		<label><?php echo $this->translator('enterprise_currency'); ?>:</label>
	            <select id="currency" name="currency" style="width:170px">
	                <option value="">---</option>
	                <?php foreach($this->currency as $row):?>
	                <option <?php if($this->enterprise->currency == $row->currency_name):?>selected<?php endif;?> value="<?php echo $row->currency_name;?>"><?php echo $row->currency_name;?></option>
	                <?php endforeach;?>
	            </select>
        	</div>
            <div id="rate" style="float: left; display: none;">
            	<label style="width: 40px;"><?php echo $this->translator('enterprise_rare_currency'); ?>: </label>
            	<input name="rate_input" id="rate_input" type="text" style="height: 20px;" >
            </div>
        </div>
		<script>
			// Thay doi loai tien te 
			$("#currency").change(function() {
				var new_value = $(this).val();
				if(new_value != "<?php echo $this->enterprise->currency;?>")
		        {
					$("#rate").show("slow");				      	
					$("#note_rate").show("slow");
		        }
		        else
		        {
		      		$("#rate").hide("slow");				      	
		      		$("#note_rate").hide("slow");	
		      		$("#rate_input").val("");
		        }
			});
		</script>
        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_contact_email'); ?>:</label>
            <input type="text" id="contact_email" name="contact_email" style="width: 300px" value="<?php if (null != $this->enterprise && null != $this->enterprise->contact_email) : ?><?php echo $this->escape($this->enterprise->contact_email); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_contact_tel'); ?>:</label>
            <input type="text" id="contact_tel" name="contact_tel" style="width: 170px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->contact_tel) : ?><?php echo $this->escape($this->enterprise->contact_tel); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_contact_fax'); ?>:</label>
            <input type="text" id="contact_fax" name="contact_fax" style="width: 170px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->contact_fax) : ?><?php echo $this->escape($this->enterprise->contact_fax); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_contact_address'); ?>:</label>
            <input type="text" id="contact_address" name="contact_address" style="width: 300px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->contact_address) : ?><?php echo $this->escape($this->enterprise->contact_address); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label style="line-height:15px;height:1px">&nbsp;</label>
            <span style="font-weight:bold;"><?php echo $this->translator('enterprise_account');?> VND:</span>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_name'); ?>:</label>
            <input type="text" id="bank_name_vnd" name="bank_name_vnd" style="width: 300px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_name_vnd) : ?><?php echo $this->escape($this->enterprise->bank_name_vnd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_account'); ?>:</label>
            <input type="text" id="bank_account_vnd" name="bank_account_vnd" style="width: 170px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_account_vnd) : ?><?php echo $this->escape($this->enterprise->bank_account_vnd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_account_owner'); ?>:</label>
            <input type="text" id="bank_account_owner_vnd" name="bank_account_owner_vnd" style="width: 300px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_account_owner_vnd) : ?><?php echo $this->escape($this->enterprise->bank_account_owner_vnd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label style="line-height:15px;height:1px">&nbsp;</label>
            <span style="font-weight:bold;"><?php echo $this->translator('enterprise_account');?> USD:</span>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_name'); ?>:</label>
            <input type="text" id="bank_name_usd" name="bank_name_usd" style="width: 300px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_name_usd) : ?><?php echo $this->escape($this->enterprise->bank_name_usd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_account'); ?>:</label>
            <input type="text" id="bank_account_usd" name="bank_account_usd" style="width: 170px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_account_usd) : ?><?php echo $this->escape($this->enterprise->bank_account_usd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_bank_account_owner'); ?>:</label>
            <input type="text" id="bank_account_owner_usd" name="bank_account_owner_usd" style="width: 300px"  value="<?php if (null != $this->enterprise && null != $this->enterprise->bank_account_owner_usd) : ?><?php echo $this->escape($this->enterprise->bank_account_owner_usd); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_registration_number'); ?>:</label>
            <input type="text" id="registration_number" name="registration_number" style="width: 300px" value="<?php if (null != $this->enterprise && null != $this->enterprise->registration_number) : ?><?php echo $this->escape($this->enterprise->registration_number); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_registration_date'); ?>:</label>
            <input type="text" id="registration_date" name="registration_date" style="width: 100px" value="<?php if (null != $this->enterprise && null != $this->enterprise->registration_date) : ?><?php echo date("d/m/Y",strtotime($this->enterprise->registration_date)); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_registration_city'); ?>:</label>
            <input type="text" id="registration_city" name="registration_city" style="width: 300px" value="<?php if (null != $this->enterprise && null != $this->enterprise->registration_city) : ?><?php echo $this->escape($this->enterprise->registration_city); ?><?php endif; ?>" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_frontend_active'); ?>:</label>
            <select id="frontend_active" name="frontend_active" style="width:170px">
                <option value="0">---</option>
                <option value="1" <?php if (null != $this->enterprise && 1 == $this->enterprise->frontend_active) : ?>selected="true"<?php endif; ?> ><?php echo $this->translator('enterprise_frontend_status_active'); ?></option>
                <option value="0" <?php if (null != $this->enterprise && 0 == $this->enterprise->frontend_active) : ?>selected="true"<?php endif; ?> ><?php echo $this->translator('enterprise_frontend_status_inactive'); ?></option>
            </select>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_backend_active'); ?>:</label>
            <select id="backend_active" name="backend_active" style="width:170px">
                <option value="0">---</option>
                <option value="1" <?php if (null != $this->enterprise && 1 == $this->enterprise->backend_active) : ?>selected="true"<?php endif; ?> ><?php echo $this->translator('enterprise_backend_status_active'); ?></option>
                <option value="0" <?php if (null != $this->enterprise && 0 == $this->enterprise->backend_active) : ?>selected="true"<?php endif; ?> ><?php echo $this->translator('enterprise_backend_status_inactive'); ?></option>
            </select>
        </div>

        <hr/>
		<?php 
			$enterprise_id = $this->enterprise->id;
			$pathMap 	   = "images/maps/".$enterprise_id.".png";	
		?>		
		<div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('enterprise_map'); ?>:</label>
			<?php 
				if(file_exists($pathMap)):
			?>
				<img  id="enterpriseMapImage" width="70" height="70" style="border: 1px solid #CCCCCC;" src="<?php echo $this->APP_STATIC_SERVER.'/images/maps/'.$enterprise_id.".png"?>">	
				<a href="javascript: return void(0);" onclick="javascript:$('#editEnterpriseMap').trigger('click');"><?php echo $this->translator("enterprise_edit_map");?></a>				
				<div style="display:none;">
					<?php echo $this->widget("bizprofile","map",array("has_dialog"=>true));?>
				</div>				
			<?php else:?>
				<input type="file" name="map" />
			<?php endif;?>
        </div>
		
        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('enterprise_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
            <button type="reset"><span><?php echo $this->translator('enterprise_reset_button'); ?></span></button>
        </div>
        <?php endif;?>
    </div>
</div>
</form>

<script type="text/javascript">

$(document).ready(function() {

    /**
    * Create datepicker instances
    */
    $('#registration_date').datepicker({ dateFormat: 'dd/mm/yy' });
    
    // EDIT - STAR : KHANH; 25/04/2011; Kiem tra so dien thoai co dau +
    $.validator.addMethod('check_fonenumber', function(value) {
		var str = value;
		var the_char = str.charAt(0);
		if(the_char=="+")
		{
			str = str.split(' ').join(''); ;	// Remove Spaces
			var len = str.length;
			for(i=1; i<len; i++) // bat dau tu ky tu sau dau "+"
			{
				if(str[i]=="0")
				{
					
				}
				else if(!parseInt(str[i]))				
				{ return false; }	
			}
			
		}
		else
		{ return false;	}
	
		return true;
	});
	// EDIT - STOP
	
    $('#editEnterpriseForm').validate({
        rules: {
            company_name_vn: {
                required: true,
                maxlength: 255
            },
            company_name_en:{
                maxlength: 255
            },
            contact_email:{
                required: true,
                email:true
            },
            registration_number:{
                required: true
            },
            registration_date:{
                required: true
            },
            registration_city:{
                required: true
            },
            currency:{
                required: true,
            },
            contact_tel:{
                required: true,
                //number: true,
                check_fonenumber: true
            },
            contact_fax:{
                required: true,
                //number: true,
                check_fonenumber: true
            },
            contact_address:{
                required: true
            }
            ,
            bank_name_vnd:{
                required: true
            }
            ,
            bank_account_vnd:{
                required: true
            }
            ,
            bank_account_owner_vnd:{
                required: true
            }
            ,
            rate_input:{
            	number: true            	
            }
        },
        messages: {
            company_name_vn: {
                required: "<?php echo $this->translator('enterprise_company_name_vn_required'); ?>",
                maxlength: "<?php echo $this->translator('enterprise_company_name_vn_maxlength'); ?>"
            },
            company_name_en: "<?php echo $this->translator('enterprise_company_name_en_maxlength'); ?>",
            contact_email: {
                required: "<?php echo $this->translator('enterprise_contact_email_required'); ?>",
                email: "<?php echo $this->translator('enterprise_invalid_email'); ?>"
            },
            registration_number: "<?php echo $this->translator('enterprise_registration_number_required'); ?>",
            registration_date: "<?php echo $this->translator('enterprise_registration_date_required'); ?>",
            registration_city: "<?php echo $this->translator('enterprise_registration_city_required'); ?>",
            currency: "<?php echo $this->translator('enterprise_currency_required'); ?>",
            contact_tel: {
                required: "<?php echo $this->translator('enterprise_contact_tel_required'); ?>",
                check_fonenumber: "<?php echo $this->translator('enterprise_contact_tel_invalid_number'); ?>"
            },
            contact_fax: {
                required: "<?php echo $this->translator('enterprise_contact_fax_required'); ?>",
                check_fonenumber: "<?php echo $this->translator('enterprise_contact_fax_invalid_number'); ?>"
            },
            contact_address: "<?php echo $this->translator('enterprise_contact_address_required'); ?>",
            bank_name_vnd: "<?php echo $this->translator('enterprise_bank_name_required'); ?>",
            bank_account_vnd: "<?php echo $this->translator('enterprise_bank_account_required'); ?>",
            bank_account_owner_vnd: "<?php echo $this->translator('enterprise_bank_account_owner_required'); ?>",
            rate_input: {
            	number: "<?php echo $this->translator('enterprise_rate_invalid_number'); ?>"            	
            }
           
        }
    });
});
</script>
